import router from './router'
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style
import getPageTitle from '@/utils/get-page-title'
import settings from '@/settings'

NProgress.configure({ showSpinner: false }) // NProgress Configuration

// 路由拦截器，每次刷新路由时执行
router.beforeEach(async (to, from, next) => {

  // 开始进度条
  NProgress.start()

  // 如果有权限，就成功进入页面
  if (to.meta.isAuth === 0) {
    next();
  } else {
    // 鉴权
    if (!sa.isAuth(to.path)) {
      next('403');
    } else {
      next();
    }
    // set 页面标题 针对控制台
    document.title = getPageTitle(to.meta.title)
  }



  // 结束进度条
  NProgress.done();
})

router.afterEach(() => {

  // 关闭进度条
  NProgress.done()

  // 解决每次切换视图时table渲染不正确的bug
  setTimeout(function () {
    var view = sa.currView();
    if (view && view.$refs['data-table']) {
      view.$refs['data-table'].doLayout();
    }
  }, 500);
})
